<template>
    <Modal
            width="800"
            v-model="visible"
            :title="title"
            :key="key"
            :loading="Loading"
    >
        <div style="width: 80%;padding-left: 10%;padding-right: 10%">
            <Spin size="large" fix v-if="Loading"></Spin>
            <Form :label-width="130" ref="formValidate" :model="formValidate"
                  :rules="ruleValidate" :disabled="disableSubmit">
                <Form-item label="救助对象类别:" prop="dbzp0001">
                    <c-dict-select v-model="formValidate.dbzp0001" dictCode="systemsubtype" :width="300"/>
                </Form-item>
                <Form-item label="打印模板名称:" prop="dbzp0002">
                    <c-dict-select v-model="formValidate.dbzp0002" dictCode="printtemplatename" :width="300"/>
                </Form-item>
                <Form-item label="模版信息:" prop="dbzp0004">
                    <Input v-model="formValidate.dbzp0004" type="textarea" placeholder="请输入模版信息"/>
                </Form-item>

                <Form-item label="是否有效:" prop="dbzp0003">
                    <c-dict-select v-model="formValidate.dbzp0003" dictCode="yesorno" :width="300"/>
                </Form-item>

                <Form-item label="左右:">
                    <Select v-model="formValidate.dbzp0005" style="width: 300px">
                        <Option value="0">左侧页面</Option>
                        <Option value="1">右侧页面</Option>
                    </Select>
                </Form-item>
            </Form>
        </div>
        <div slot="footer">
            <Button @click="cancel">取消</Button>
            <template v-if="!disableSubmit">
                <Button type="primary" @click="ok">确定</Button>
            </template>
        </div>
    </Modal>
</template>

<script>
    import {postAction} from '@/api/request'

    export default {
        data() {
            return {
                modal1: false,
                visible: false,
                disableSubmit: false,
                title: "",
                model: {},
                formValidate: {
                    yjaa0002: null
                },
                ruleValidate: {
                    dbzp0001: [
                        {required: true, message: '请选择救助对象类别', trigger: 'blur'}
                    ],
                    dbzp0002: [
                        {required: true, message: '请选择打印模板名称', trigger: 'blur'}
                    ],
                    dbzp0003: [
                        {required: true, message: '请填写模版信息', trigger: 'blur'}
                    ],
                    dbzp0004: [
                        {required: true, message: '是否有效', trigger: 'blur'}
                    ],
                },
                key: "",
                url: "/api/ac/subsistence/Ss21010Service/insert",
                Loading: false,
            }
        },
        methods: {
            ok() {
                var that = this;
                this.$refs['formValidate'].validate((valid) => {
                    if (valid) {
                        that.submitFrom();
                    }
                })
            },
            submitFrom() {
                var that = this;
                that.Loading = true;
                postAction(that.url, that.formValidate).then((res) => {
                    if (res.data.errcode != 0) {
                        this.$Message.error(res.data.errmsg);
                    } else {
                        that.$Message.success("保存完成！");
                        this.$emit('ok');
                        this.visible = false;
                    }
                }).finally(() => {
                    that.Loading = false;
                });
            },
            cancel() {
                this.visible = false;
            },
            add() {
                this.edit({});
            },
            edit(row) {
                if (row.id) {
                    this.url = "/api/ac/subsistence/Ss21010Service/update";
                } else {
                    this.url = "/api/ac/subsistence/Ss21010Service/insert";
                }
                this.visible = true
                this.formValidate = Object.assign({}, row);

            },
        }
    }
</script>

<style scoped>

</style>